export default function (LoadingConstructor) {
  LoadingConstructor.prototype.close = function () {
    this.visible = false
    if (this.$el && this.$el.parentNode) {
      this.$el.parentNode.removeChild(this.$el)
    }
    this.$destroy()
  }

  // singleton mode
  const LoadingInstance = ((options) => {
    let instance
    return function () {
      if (!instance) {
        instance = new LoadingConstructor({
          el: document.createElement('div'),
          data: {
            ...options,
            visible: true
          }
        })
        document.body.appendChild(instance.$el)
      }
      return instance
    }
  })()

  return LoadingInstance
}
